package com.wxw.BaseLibrary.component;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.TextView;

/**
 * Created by david on 2015-11-10.
 */
public class BorderTextView extends TextView {
    private int border_width = 2;
    private int border_color = Color.parseColor("#c7c7c7");
    private boolean hasShadow = false;

    public BorderTextView(Context context) {
        super(context);
    }

    public BorderTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public void setHasShadow(boolean hasShadow) {
        this.hasShadow = hasShadow;
    }

    public void setBorder_width(int border_width) {
        this.border_width = border_width;
    }

    public void setBorder_color(int border_color) {
        this.border_color = border_color;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        Paint paint = new Paint();
        paint.setColor(border_color);
        if (hasShadow) {
            canvas.drawLine(0, this.getHeight() - border_width, this.getWidth() - border_width, this.getHeight() - border_width, paint);
            canvas.drawLine(this.getWidth() - border_width, 0, this.getWidth() - border_width, this.getHeight() - border_width, paint);
        } else {
            canvas.drawLine(0, 0, this.getWidth() - border_width, 0, paint);
            canvas.drawLine(0, 0, 0, this.getHeight() - border_width, paint);
            canvas.drawLine(this.getWidth() - border_width, 0, this.getWidth() - border_width, this.getHeight() - border_width, paint);
            canvas.drawLine(0, this.getHeight() - border_width, this.getWidth() - border_width, this.getHeight() - border_width, paint);
        }
        super.onDraw(canvas);
    }
}
